<?php
namespace Common\Controller;
use Common\Controller\BaseController;
/**
 * admin 基类控制器
 */
class AdminBaseController extends BaseController{

	//分页数
	public $total_page = 10;

	/**
	 * 初始化方法
	 */
	public function _initialize(){

		parent::_initialize();

		$auth=new \Think\Auth();

		$rule_name=MODULE_NAME.'/'.CONTROLLER_NAME.'/'.ACTION_NAME;

		//判断会话是否过期
		if (time() - session('user.session_start_time') > C('SESSION_OPTIONS')['expire']) {
			session_destroy();//真正的销毁在这里！
			$this->redirect("/Home/Admin/index");

		}else{

			if(empty(session('user.id'))){

				if(session('user.email')){

					$this->redirect("/Home/Admin/activation_fail");

				}else{

					$this->redirect("/Home/Admin");
				}

			}else{

				$result=$auth->check($rule_name,session('user.id'));

				if(!$result){
					$this->error('您没有权限访问');
				}else{
					$_SESSION['user']=array(
						'id'=>session('user.id'),
						'username'=>session('user.username'),
						'avatar'=>session('user.avatar'),
						'session_start_time'=>time()
					);
				}
			}
		}

	}




}

